import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ExtraBenefitProvider} from "../../../providers/policy/extra-benefit/extra-benefit";
import * as moment from 'moment';
import {LoadingService} from "../../../services/common/loading.service";

/**
 * Generated class for the ExtraBenefitPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-extra-benefit',
  templateUrl: 'extra-benefit.html',
    providers: [ExtraBenefitProvider, ExtraBenefitProvider, LoadingService]
})
export class ExtraBenefitPage {

    policyId: any;
    dataList: any;

    moment = moment;

  constructor(public navCtrl: NavController,
              private extraBenefitProvider: ExtraBenefitProvider,
              private loadingService: LoadingService,
              public navParams: NavParams) {
      this.policyId = this.navParams.get('id');
  }

  ionViewDidLoad() {
      this.getExtraBenefitList();
  }

  getExtraBenefitList() {
      this.loadingService.showLoading();
      this.extraBenefitProvider.getExtraBenefit(this.policyId).subscribe(res => {
          console.log(res);
          this.dataList = res;
          this.loadingService.dismissLoading();
      }, error2 => {
          this.loadingService.dismissLoading();
      });
  }

    pullDownRefresh(refresher) {
        this.extraBenefitProvider.getExtraBenefit(this.policyId).subscribe(res => {
            this.dataList = res;
            refresher.complete();
        }, error2 => {
            refresher.complete();
        });
    }

    /**
     * 返回
     */
  goBack() {
      this.navCtrl.pop();
  }

}
